package com.example.controller;

import com.example.config.CustomException;
import com.example.config.LogEnable;
import com.example.entity.SysUser;
import com.example.service.SysUserService;
import io.reactivex.rxjava3.internal.schedulers.NewThreadWorker;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhangW
 * @create 2025-01-09-8:52
 */
@RestController
@RequestMapping("test/user")
public class TestController {

    private final SysUserService service;

    public TestController(SysUserService service) {
        this.service = service;
    }

    @PostMapping("list")
    public List<SysUser> list(){
        List<SysUser> list = service.list();
        return list;
    }

    @LogEnable
    @PostMapping("update")
    public void update(@RequestBody SysUser data) {
        if (data!=null){
            throw new CustomException("请重新上传");
        }
        service.updateById(data);
    }

    @PostMapping("add")
    public void add (@RequestBody SysUser data){
        service.save(data);
    }
}
